package com.rfs.suanfa;

/**
 * @author renfushuai
 * @date 2022/2/8
 */
public class 链表翻转 {
    static class ListNode {
        int val;

        public ListNode() {
        }

        private ListNode next;

        public ListNode(int v) {
            val = v;
        }

        public ListNode(int v, ListNode l) {
            this.val = v;
            this.next = l;
        }
    }

    public ListNode reverseList(ListNode head) {
        ListNode prev = null;//前指针节点
        ListNode curr = head;// 当前指针
        while (curr != null) {
            ListNode temp = curr.next;
            curr.next=prev;//当前节点指向前面的节点
            prev = curr;//前指针后移
            curr=temp;//当前指针后移

        }
        return prev;
    }
}
